#pragma once
#include "base/noncopyable.h"
#include "base/function.hpp"
#include "base/config.h"

#include <vector>
namespace net_tools{
class Eventloop;
namespace base{
class Channel;
} // namespace base
namespace net{
class Connect;
class Heartbeat;
class Connectpool : net_tools::base::noncopyable{
 public:
  Connectpool(net_tools::Eventloop* eventloop,int size = _C::CONNECT_POOL_DEFAULT_SIZE);
  ~Connectpool(){};
  Connect* Get_Connect(net_tools::base::Channel* channel);
  void Free_Connect(Connect* old_Connect);
  int Get_connect_number(){return connect_number;};

  void Set_heartbeat(connect_func heartbeat_lose_func);
  void Start_heartbeat();
  void Stop_heartbeat();
  //Need in right thread;
  void Add_heartbeat(Connect* connect);
  //Need in right thread;
  void Del_heartbeat(Connect* connect);
 private:
  std::vector<Connect*> connect_free_vector_;
  int                   connect_number;
  net_tools::Eventloop* eventloop_;
  connect_func          heartbeat_lose_func_;
  Heartbeat*            heartbeat_;
};

} // namespace net
} // namespace net_tools